export function MP() {
  const p1 = new Promise((resolve, reject) => {
    if(window.AMap){
      resolve(window.AMap)
    }else{
      let script = document.createElement('script')
      script.type = 'text/javascript'
      script.src = 'https://webapi.amap.com/maps?v=1.4.15&key=582d8339d1a061e2a972565508e6e16d&plugin=AMap.GraspRoad,Map3D,ElasticMarker,AMap.ControlBar,AMap.MouseTool,AMap.DistrictSearch,AMap.Geocoder&callback=initAMap'
      script.onerror = reject
      document.head.appendChild(script)
    }
    window.initAMap = ()=> {
      resolve(window.AMap)
    }
  })
  const p2 = new Promise((resolve, reject) => {
    let script2 = document.createElement('script')
    script2.type = 'text/javascript'
    script2.src = '//webapi.amap.com/ui/1.0/main.js'
    script2.onerror = reject
    script2.onload = function () {
      resolve('success')
    }
    document.head.appendChild(script2)
  })
  return Promise.all([p1, p2])
    .then(result => {
      return result[0]
    }).catch(e => {
      console.log(e)
    })
}
